#!/bin/bash

BRANCH=""
OSC_USAER=""
OSC_PASS=""
ARCH="x86_64"
UPDATE_TIME=""
EPOL=""
INIT_PATH="~"

yum_repo=${INIT_PATH}/update-release.repo

# obs project
obs_project=`echo ${BRANCH//-/:}`
if [ x$EPOL = "x1" ]; then
	obs_project="${obs_project}:Epol"
fi

# oscrc
mkdir -p /root/.config/osc
> /root/.config/osc/oscrc
cat > /root/.config/osc/oscrc << EOF
[general]
apiurl=http://117.78.1.88
no_verify=1

[http://117.78.1.88]
user=$OSC_USAER
pass=$OSC_PASS
EOF

# check.config
sed -i "s#yum_repo=.*#yum_repo=${yum_repo}#g" ${INIT_PATH}/check.config
sed -i "s#obs_repo=.*#obs_repo=standard_${ARCH}#g" ${INIT_PATH}/check.config
sed -i "s#obs_arch=.*#obs_arch=${ARCH}#g" ${INIT_PATH}/check.config

# yum repo
> ${yum_repo}
cat > ${yum_repo} << EOF
[OS]
name=OS
baseurl=https://repo.openeuler.org/${BRANCH}/OS/${ARCH}/
enabled=1
gpgcheck=0

[everything]
name=everything
baseurl=https://repo.openeuler.org/${BRANCH}/everything/${ARCH}/
enabled=1
gpgcheck=0

[epol]
name=epol
baseurl=https://repo.openeuler.org/${BRANCH}/EPOL/${ARCH}/
enabled=1
gpgcheck=0

[update]
name=update
baseurl=https://repo.openeuler.org/${BRANCH}/update/${ARCH}/
enabled=1
gpgcheck=0

[update-epol]
name=update-epol
baseurl=https://repo.openeuler.org/${BRANCH}/EPOL/update/${ARCH}/
enabled=1
gpgcheck=0

[update_${UPDATE_TIME}]
name=update_${UPDATE_TIME}
baseurl=http://121.36.84.172/repo.openeuler.org/${BRANCH}/update_${UPDATE_TIME}/${ARCH}/
enabled=1
gpgcheck=0

[update_${UPDATE_TIME}-epol]
name=update_${UPDATE_TIME}-epol
baseurl=http://121.36.84.172/repo.openeuler.org/${BRANCH}/EPOL/update_${UPDATE_TIME}/${ARCH}/
enabled=1
gpgcheck=0
EOF
